FROM ubuntu:20.04

WORKDIR /tmp/res
COPY ./res ./

# 设置驱动路径环境变量
ARG ASCEND_BASE=/usr/local/Ascend
ENV LD_LIBRARY_PATH=\
$ASCEND_BASE/driver/lib64:\
$ASCEND_BASE/driver/lib64/common:\
$ASCEND_BASE/driver/lib64/driver:\
$ASCEND_BASE/driver/tools/hccn_tool/:/lib64:


# overwrite the default 'sh' shell with 'bash'
SHELL ["/bin/bash","-c"]

RUN mkdir ~/.pip
# Use printf instead of 'echo -e'(-e to parse \n), since -e will be written into the file as text content
RUN printf "[global]\nindex-url = https://mirrors.huaweicloud.com/repository/pypi/simple\ntrusted-host = mirrors.huaweicloud.com" >> ~/.pip/pip.conf
#RUN echo -e "[global]\nindex-url = https://mirrors.huaweicloud.com/repository/pypi/simple\ntrusted-host = mirrors.huaweicloud.com" >> ~/.pip/pip.conf
RUN sed -i "s@http://.*archive.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
RUN sed -i "s@http://.*security.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list


# 1 环境准备
## Skip the timezone selection prompt
ENV TZ=US
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y gcc g++ make cmake libsqlite3-dev zlib1g-dev libssl-dev libffi-dev libbz2-dev liblzma-dev wget procps pciutils kmod net-tools udev systemd python3 python3-pip

# 2 安装CANN
ARG CANN_TOOLKIT=Ascend-cann-toolkit_8.0.0.alpha002_linux-x86_64.run
ARG KERNEL_PKG=Ascend-cann-kernels-310p_8.0.0.alpha002_linux-x86_64.run

RUN	chmod +x $CANN_TOOLKIT && ./$CANN_TOOLKIT --quiet --full --install-path=$ASCEND_BASE --install-for-all
RUN chmod +x $KERNEL_PKG && ./$KERNEL_PKG --quiet --install --install-for-all

# 3 Clean the temp installation files
RUN rm -rf *
